package com.jx.servicrimpl;

import com.jx.dao.CatDao;
import com.jx.daoimpl.CatDaoImpl;
import com.jx.model.Category;
import com.jx.service.CatService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class CatServiceImpl implements CatService {
	//定义CatDao类型的引用catdao指向CatDaoImpl对象，用以调用dao层显示商品分类信息的方法
	CatDao catdao = new CatDaoImpl();
	//显示商品分类的方法
	@Override
	public JSONObject showCat(int start,int pageSize) {
		// TODO Auto-generated method stub
		JSONObject cs = new JSONObject();
		cs.put("rows",JSONArray.fromObject(catdao.showCatrgory(start, pageSize)));
		cs.put("total", catdao.showCategoryCount());
		return cs;
	}
	//增加商品分类
	@Override
	public boolean addCat(Category c) {
		// TODO Auto-generated method stub
		return catdao.addCategory(c);
	}
	//删除商品分类
	@Override
	public boolean delCat(int cid) {
		// TODO Auto-generated method stub
		return catdao.delCategory(cid);
	}
	//模糊查询分页
	@Override
	public JSONObject showCat(String cname, int start, int pageSize) {
		// TODO Auto-generated method stub
		JSONObject cs = new JSONObject();
		cs.put("rows",JSONArray.fromObject(catdao.showCategory(cname, start, pageSize)));
		cs.put("total", catdao.showCategoryCount());
		return cs;
	}
	//更新商品分类
	@Override
	public boolean updCat(Category c) {
		// TODO Auto-generated method stub
		return catdao.updCategory(c);
	}

}
